﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Security.Cryptography;
using System.Text;

namespace wuliuback
{
    public partial class PublishGoods : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string goodsId = Request["goods_id"];
            string fromProvince = Request["from_province"];
            string fromCity = Request["from_city"];
            string fromCounty = Request["from_county"];
            string toProvince = Request["to_province"];
            string toCity = Request["to_city"];
            string toCounty = Request["to_county"];
            string course = Request["course"];
            string goodsType = Request["goods_type"];
            string truckInfo = Request["truck_info"];
            string weight = Request["weight"];
            string unit = Request["unit"];
            string note = Request["note"];
            string userId=Request["user_id"];
            string createdTime = DateTime.Now.ToString();
            string mobile=Request["mobile"];;
            string contactName=Request["contact_name"];
            string truck_type = Request["truck_type"];
            string truck_length = Request["truck_length"];
            string remain_length = Request["remain_length"];
            string fee = Request["fee"];
            string status="1";

            string code = "";
            string msg = "";


            String sql = "";
            DbHelper dbHelper = new DbHelper();
            if (goodsId == null || goodsId.Length <= 0)
            {
                sql = "insert into t_goods(from_province,from_city,from_county,to_province,to_city,to_county,"
                                         + "course,goods_type,truck_info,weight,unit,note,user_id,created_time,mobile,contact_name,status,"
                                         + "truck_type,truck_length,remain_length,fee)"
                                  + "values('" + fromProvince + "','" + fromCity + "','" + fromCounty + "','" + toProvince + "','" + toCity + "','" + toCounty + "','"
                                         + course + "','" + goodsType + "','" + truckInfo + "','" + weight + "','" + unit + "','" + note + "','" + userId + "','" + createdTime + "','"
                                         + mobile + "','" + contactName + "','" + status + "','" + truck_type + "','" + truck_length + "','" + remain_length +"','"+fee+ "')";
                if (dbHelper.Insert(sql))
                {
                    code = "0";
                    msg = "成功发布";
                }
                else
                {
                    code = "-1";
                    msg = "发布失败";
                }
            }
            else
            {
                sql = "update t_goods set from_province='" + fromProvince + "',from_city='" + fromCity + "',from_county='" + fromCounty + "',to_province='" + toProvince + "',to_city='" + toCity + "',to_county='" + toCounty + "',"
                                         + "course='" + course + "',goods_type='" + goodsType + "',truck_info='" + truckInfo + "',weight='" + weight + "',unit='" + unit + "',note='" + note + "',user_id='" + userId + "',created_time='" + createdTime + "',mobile='" + mobile + "',contact_name='" + contactName
                                         + "',truck_type='" + truck_type + "',truck_length='" + truck_length + "',remain_length='" + remain_length + "',status='" + status + "',fee='" + fee+"' "
                                         + "where goods_id=" + goodsId;
                if (dbHelper.Update(sql))
                {
                    code = "0";
                    msg = "成功更新";
                }
                else
                {
                    code = "-1";
                    msg = "更新失败";
                }
            }
            
            Response.Output.WriteLine("{\"code\":\""+code+"\",\"msg\":\""+msg+"\"}");
        }
    }
}
